<template>
	<view class="page-fade-in" :style="{opacity: pageOpc}">
		<template v-if="pageOpc">
			<view class="content">
				<view class="table-info flexWrapNo">
					<view class="big">{{numText}}</view>
					<view class="info">
						<view class="table-name">{{characters}}
							<view class="status"
								:class="{busy:tableInfo.status==2||tableInfo.status==99,repair:tableInfo.status==3}">
								{{tableInfo.status==2||tableInfo.status==99?'使用中':tableInfo.status==3?'维护':'空闲'}}
							</view>
						</view>
						<view class="store-name">
							默认就近一小时开台
						</view>
					</view>
				</view>
				<view class="select-box flexWrapNo" v-if="!renew_order_id">
					<view class="select-item" :class="{active:currmentIndex==index}" v-for="(item,index) in mealList"
						:key="index" @tap="changeMeal(index)">
						<view class="select-top flexWrap">
							<text v-if="index==0">默认</text>
							<text v-else>优惠{{index}}</text>
							<image src="../static/user/selected.png" class="select-icon" v-if="currmentIndex==index">
							</image>
							<image src="../static/user/select.png" class="select-icon" v-else></image>
						</view>
						<view class="select-bottom flexWarpColumn">
							<view class="name">{{item.p_name}}</view>
							<view class="price">{{item.p_price}}元/<block v-if="index!=0">{{item.duration}}
								</block>小时</view>
						</view>
					</view>
				</view>
				<view class="time-box">
					<view class="top-box flexWrap">
						<view>
							<view class="title">选时间</view>
							<view>价格:{{tableInfo.price}}元/小时</view>
						</view>
						<view class="hours" v-if="currmentIndex>0">{{mealList[currmentIndex].duration}}h</view>
					</view>
					<view class="date-select-box flexWrapNo" v-if="order_type=='make_appointment'">
						从
						<view class="date-box flexWrapNo">
							<picker @change="changeDate" :value="dateIndex" :range="dateList" range-key="riqis">
								<view class="flexWrapNo">
									<view class="uni-input">{{dateList[dateIndex].riqis}}</view>
									<image src="../static/home/down-icon.png" class="down-icon"></image>
								</view>
							</picker>
						</view>
						<picker mode="time" :value="currmentTime" :start="startTime" end="24:00"
							@change="bindTimeChange">
							<view class="time flexWrapNo">
								<view class="reduce-btn">
									<text v-for="(item,index) in currmentTime.split(':')[0].split('')">{{item}}</text>
								</view>
								<view class="colon">:</view>
								<view class="reduce-btn">
									<text v-for="(item,index) in currmentTime.split(':')[1].split('')">{{item}}</text>
								</view>
							</view>
						</picker>
						开始
					</view>
					<scroll-view scroll-x enable-flex :scroll-into-view="scrollIndex" class="lattice-box">
						<view class="lattice" :id="'lattice-'+index"
							:class="{white:index>pastHour,blue:index>=currentHour&&index<=allHour,red:item.order_type!=0}"
							v-for="(item,index) in hoursList" :key="index">
							{{item.time}}
							<!-- <view class="lable"></view> -->
						</view>
					</scroll-view>
					<view class="select-time-box flexWrap">
						<view class="select-time">
							<view class="title">已选时间</view>
							<view>{{currmentDate}} {{currmentTime}}～<text v-if="allHour>23">次日</text>{{nextTime}}</view>
						</view>
						<view class="operation-box flexWrapNo" v-if="currmentIndex<1">
							<view class="reduce-btn" @tap="reduce()">-</view>
							<view class="operation-num">{{totalHour}}h</view>
							<view class="increase-btn" @tap="increase()">+</view>
						</view>
					</view>
				</view>
				<view class="explain-box">
					<view class="explain-cont">
						<block v-if="currmentIndex==0">
							<view v-html="tableInfo.immediately_opening_explain"></view>
						</block>
						<view v-html="mealList[currmentIndex].p_tx_sm+(mealList[currmentIndex].supplement||'')" v-else>
						</view>
					</view>
				</view>
				<view class="btn-box">
					<view class="total-box">
						合计
						<text class="price" v-if="currmentIndex>0">{{mealList[currmentIndex].p_price||0}}</text>
						<text v-else class="price">{{totalPrice||0}}</text>
						<text class="original-price"
							v-if="currmentIndex>0">{{Number(tableInfo.price*mealList[currmentIndex].duration).toFixed(2)}}</text>
					</view>
					<view class="pay-btn" @tap="goConfirm()">确认支付并下单</view>
				</view>
				<view class="tips-box flexWarpCenterColumn" v-if="continueShow">
					<view class="tips-name">重要提醒</view>
					<image src="../static/public/couponClose.png" class="close-btn" @tap="closeContinue()"></image>
					<block v-if="serviceMinNum>=12">
						<view class="tips-text">
							{{continueMsg}}
						</view>
					</block>
					<block v-else>
						<view class="tips-text">
							此桌台距离预约单仅剩不足15分钟，无法开台
						</view>
						<view class="tips-text">
							您还可以更换桌台
						</view>
					</block>
					<view class="tips-btn-box flexWrap">
						<view class="tips-btn" @tap="continueOrder()" v-if="serviceMinNum>=12">立即开台</view>
						<view class="tips-btn" @tap="showActionSheet()">换桌</view>
					</view>
				</view>
				<view class="mask-wrap" v-if="continueShow"></view>
			</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageOpc: 0,
				currmentIndex: 0,
				currmentDate: "",
				currentHour: 0,
				startTime: "",
				currmentTime: "",
				nextTime: "",
				totalHour: 1,
				pastHour: 0,
				dateIndex: 0,
				nextIndex: 0,
				dateList: [],
				status: 1,
				equipment_id: "",
				tableInfo: {},
				mealList: [{
					p_name: "立即开台"
				}],
				hoursList: [],
				store_id: "",
				allHour: 0,
				type: 1,
				renew_order_id: "",
				couponShow: false,
				couponList: [],
				couponLenth: 0,
				minReservationTime: 0, //最低预定时长
				minRenewalTime: 0, //最低续费时长
				days_in_advance: 0,
				orderTime: "",
				order_type: "",
				scrollIndex: "",
				numText: "",
				characters: "",
				serviceMinNum:"",
				continueShow:false,
				is_confirm:0,
				orderData:{},
				orderTotalPrice:"",
				tabList:[],
				changeList:[],
				changeLists:[],
				continueMsg:""
			}
		},
		onReady() {
			setTimeout(() => {
				this.pageOpc = 1
			}, 100)
		},
		computed: {
			totalPrice() {
				let totalPrice = 0;
				totalPrice += Number(this.totalHour * this.tableInfo.price)
				return totalPrice.toFixed(2);
			},
		},
		onLoad(ops) {
			this.equipment_id = ops.equipment_id
			this.order_type = ops.order_type
			let navtitle = ''
			navtitle = this.order_type == 'make_appointment' ? '预约开台' : '立即开台'
			uni.setNavigationBarTitle({
				title: navtitle
			})
			this.renew_order_id = ops.renew_order_id || ""
			this.store_id = ops.store_id || uni.getStorageSync('store_id')
			if (this.store_id) {
				uni.setStorageSync('store_id', this.store_id)
			}
			uni.setStorageSync('equipment_id', this.equipment_id)
			this.tableDetails();
			this.getPaymentConfig();
		},
		onShow() {
			if (!uni.getStorageSync('token')) {

			} else {
				this.getNewCoupon();
			}
		},
		onShareAppMessage() {
			return {
				path: '/pages/home/billiardsDetails?equipment_id=' + this.equipment_id + '&store_id=' + this.store_id
			};
		},
		methods: {
			yuyueTips() {
				this.$tools.showToast('当前店铺不允许预约，请到店后开台')
			},
			// 配置
			getPaymentConfig() {
				this.$request.post(this.$api.paymentConfig, {
					store_id: uni.getStorageSync('store_id')
				}, {}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code == 1) {
						if (data) {
							// this.paymentConfig=data
						} else {
							data = {
								coupon: 0,
								order_cancellation: 0,
								recharge: 0,
								wechat_payment: 0
							}
						}
						uni.setStorageSync('paymentConfig', data)
					}
				})
			},
			showCoupon() {
				this.couponShow = true
			},
			closeCoupon() {
				this.couponShow = false
			},
			// 获取新用户优惠券
			getNewCoupon() {
				this.$request.post(this.$api.newCoupon, {
					store_id: uni.getStorageSync('store_id')
				}, {
					token: true
				}).then(res => {
					let {
						data = {}
					} = res;
					uni.hideToast();
					if (res.code == 1) {
						for (let i in data) {
							data[i].num = data[i].sum
						}
						this.couponList = data
						this.couponLenth = this.couponList.length
						this.couponShow = true
					} else {
						this.couponShow = false
						uni.hideToast();
					}
				})
			},
			// 领取优惠券
			receiveCoupon() {
				this.$request.post(this.$api.receiveCoupon, {
					coupon: JSON.stringify(this.couponList),
					store_id: uni.getStorageSync('store_id')
				}, {
					token: true
				}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code == 1) {
						this.closeCoupon();
						this.$tools.showToast('领取成功')
					}
				})
			},
			goVerificaion() {
				if (this.tableInfo.status == 3 || this.tableInfo.status == 99) {
					this.$tools.showToast('对不起，请您选择其他桌，本桌正在维护或者使用中')
					return;
				}
				this.goPage('/pages/coupon/verificationCoupon')
			},
			// 选择时间
			bindTimeChange: function(e) {
				let key = Object.keys(this.tableInfo.t_date)
				if (this.dateIndex != 0) { //如果不是今天
					if (this.dateIndex == 1 && this.days_in_advance == 2) {
						if (Number(e.detail.value.split(':')[0]) + Number(this.totalHour) >= 24) {
							this.$tools.showToast('可预约时间为2天')
							return;
						}
					}
					if (this.dateIndex == 1 && this.days_in_advance == 3) {
						if (Number(e.detail.value.split(':')[0]) + Number(this.totalHour) >= 47) {
							this.$tools.showToast('可预约时间为3天')
							return;
						}
						this.hoursList = this.tableInfo.t_date[key[1]].concat(this.tableInfo.t_date[key[2]])
					}
					if (this.dateIndex == 2 && this.days_in_advance == 3) {
						if (Number(e.detail.value.split(':')[0]) + Number(this.totalHour) >= 24) {
							this.$tools.showToast('可预约时间为3天')
							return;
						}
						this.hoursList = this.tableInfo.t_date[key[1]].concat(this.tableInfo.t_date[key[2]])
					}
				} else {
					if (this.tableInfo.yuyue == '23:59') {
						this.dateIndex += 1
						if (this.currmentIndex >= 0) { //如果是预约就选择当前日期下的格子
							this.hoursList = this.tableInfo.t_date[key[this.dateIndex]] //获取当前天的格子
							this.currmentDate = this.getDate(1, this.dateIndex)
							if (this.dateIndex != 0) { //不是今天
								this.startTime = "00:00"
								this.currmentTime = "00:00"
								this.pastHour = -1
								this.currentHour = 0
								this.allHour = Number(this.totalHour) + Number(this.currentHour)
								let currmentDate = this.getDate(0) + ' ' + this.currmentTime
								this.nextTime = this.getTimeString(currmentDate, this.totalHour) //下一个小时的时间
							} else {
								this.getHoursData();
								this.hoursList = this.tableInfo.t_date[key[0]].concat(this.tableInfo.t_date[key[
									1]]) //如果是今天就获取第二天的格子
							}
						}
					}
					if (this.allHour == 47) {
						this.$tools.showToast('最多可选次日时间')
						return
					}
				}
				let selectDate=this.getDate(0,this.dateIndex)+' '+e.detail.value
				let timestamp = Date.parse(new Date())/1000;
				let selectTimestamp=new Date(selectDate).getTime()/1000;
				if(timestamp>selectTimestamp){
					console.log('>')
					let addTime=this.addMinutes(this.getDate(0)+' '+this.getTimeString(),5)
					let currmentDate=this.getDate(0)+' '+addTime
					this.currmentTime=this.getTimeString(currmentDate)
					this.nextTime=this.getTimeString(currmentDate,this.totalHour)
				}else{
					this.currmentTime=e.detail.value
					let currmentDate=this.getDate(0)+' '+this.currmentTime
					this.nextTime=this.getTimeString(currmentDate,this.totalHour)//下一个小时的时间
				}
				this.currentHour=this.currmentTime.split(':')[0]
				this.allHour=Number(this.totalHour)+Number(this.currentHour)
			},
			isToday(today, date) {
				if (!date) return;
				var d = new Date(date.replace(/-/g, "/"));
				var todaysDate = today ? new Date(today.replace(/-/g, "/")) : new Date();
				return d.setHours(0, 0, 0, 0) == todaysDate.setHours(0, 0, 0, 0);
			},
			greaterToday(today, date) {
				if (!date) return;
				var d = new Date(date.replace(/-/g, "/"));
				var todaysDate = today ? new Date(today.replace(/-/g, "/")) : new Date();
				return d.setHours(0, 0, 0, 0) > todaysDate.setHours(0, 0, 0, 0);
			},
			// 加分钟
			addMinutes(date, num) {
				var time = new Date();
				var time1 = Date.parse(date.replace(/-/g, '/'))
				time.setTime(time1 + 60000 * num);
				let hours = time.getHours() <= 9 ? '0' + time.getHours() : time.getHours()
				let minutes = time.getMinutes() <= 9 ? '0' + time.getMinutes() : time.getMinutes()
				return hours + ":" + minutes
			},
			checkTime(i) {
				if (i < 10) {
					i = "0" + i;
				}
				return i;
			},
			// 获取当前日期
			getDate(type, num) {
				num = num || 0
				console.log(type, num)
				var time = new Date();
				time.setDate(time.getDate() + num);
				let year = time.getFullYear()
				let month = time.getMonth() + 1
				let day = time.getDate()
				let fullDate = ""
				if (type == 0) {
					fullDate = year + '-' + month + '-' + day
				} else {
					fullDate = month + '月' + day + '日'
				}
				return fullDate;
			},
			// 获取当前时间
			getTimeString(currmentDate, num) {
				num = num || 0
				var time = new Date();
				var time1 = currmentDate ? Date.parse(currmentDate.replace(/-/g, '/')) : new Date()
					.getTime(); //如果传了日期就获取日期，否则获取当前时间
				time.setTime(time1 + 3600000 * num);
				let hours = time.getHours() <= 9 ? '0' + time.getHours() : time.getHours()
				let minutes = time.getMinutes() <= 9 ? '0' + time.getMinutes() : time.getMinutes()
				return hours + ":" + minutes
			},
			// 获取各个参数
			getHoursData() {
				var time = new Date();
				this.currentHour = time.getHours() //当前小时
				if ((this.tableInfo.yuyue && this.order_type != 'immediately') || this.renew_order_id) { //如果有预约时间就从预约时间开始
					let addTime = this.addMinutes(this.getDate(0) + ' ' + this.tableInfo.yuyue, 1)
					let currmentTime = this.getDate(0) + ' ' + addTime
					this.currmentTime = this.getTimeString(currmentTime)
					this.nextTime = this.getTimeString(currmentTime, this.totalHour)
					this.startTime = this.getTimeString(currmentTime)
					if (this.tableInfo.day_yuyue) { //如果有预约
						this.currentHour = this.tableInfo.yuyue.split(':')[0]
						if (this.isToday(this.getDate(0, this.dateIndex), this.tableInfo.day_yuyue)) {
							console.log('是同一天111111')
						} else {
							this.dateIndex += 1
							this.nextIndex = this.dateIndex + 1
							let key = Object.keys(this.tableInfo.t_date)
							this.hoursList = this.tableInfo.t_date[key[this.dateIndex]] //获取当前天的格子
							console.log('不是同一天111111')
						}
					}
				} else {
					this.currmentTime=this.getTimeString()//获取当前时间
					this.nextTime=this.getTimeString('',this.totalHour)//下一个小时的时间
					this.startTime=this.getTimeString()
					if(this.order_type == 'make_appointment'){
						let addTime=this.addMinutes(this.getDate(0)+' '+this.getTimeString(),5)
						let currmentTime=this.getDate(0)+' '+addTime
						this.currmentTime=this.getTimeString(currmentTime)
						this.nextTime=this.getTimeString(currmentTime,this.totalHour)
						this.startTime=this.getTimeString(currmentTime)
					}
				}
				this.allHour = Number(this.totalHour) + Number(this.currentHour)
				this.pastHour = this.currentHour - 1 //过去了多少个小时
				if (this.order_type == 'immediately') {
					this.currmentDate = this.getDate(1, this.dateIndex); //获取当前日期
				} else {
					this.currmentDate = this.tableInfo.yuyue != '23:59' ? this.getDate(1, this.dateIndex) : this.getDate(1,1); //获取当前日期
				}
				this.scrollIndex = 'lattice-' + Number(this.currentHour - 2)
				console.log(this.scrollIndex)
			},
			// 切换套餐
			changeMeal(index) {
				this.currmentIndex = index
				this.totalHour = 1 //选择的小时数恢复默认
				this.dateIndex = 0 //天数恢复默认
				let key = Object.keys(this.tableInfo.t_date)
				if (this.days_in_advance == 0 || this.days_in_advance == 1) {
					this.hoursList = this.tableInfo.t_date[key[0]]
				} else {
					this.hoursList = this.tableInfo.t_date[key[0]].concat(this.tableInfo.t_date[key[1]])
				}
				if (this.currmentIndex > 0) {
					this.totalHour = this.mealList[this.currmentIndex].duration
				}
				this.getHoursData();
			},
			// 增加时间
			increase() {
				if (this.dateIndex != 0) { //如果不是今天
					let key = Object.keys(this.tableInfo.t_date)
					if (this.days_in_advance == 1) {
						if (this.allHour >= 23) {
							this.$tools.showToast('最多可选当日时间')
							return
						}
					} else if (this.days_in_advance == 2) {
						if (this.dateIndex == 1 && this.allHour >= 23) {
							this.$tools.showToast('最多可选当日时间')
							return
						} else {
							this.hoursList = this.tableInfo.t_date[key[0]].concat(this.tableInfo.t_date[key[1]])
						}
					} else if (this.days_in_advance == 3) {
						if (this.dateIndex == 1) {
							if (this.allHour >= 47) {
								return
							} else {
								this.hoursList = this.tableInfo.t_date[key[1]].concat(this.tableInfo.t_date[key[2]])
							}
						} else {
							if (this.allHour == 23) {
								this.$tools.showToast('最多可选当日时间')
								return
							}
						}
					}
				} else {
					if (this.allHour == 47) {
						this.$tools.showToast('最多可选次日时间')
						return
					}
				}
				this.totalHour++
				this.allHour = Number(this.totalHour) + Number(this.currentHour)
				console.log(this.allHour)
				if (this.currmentIndex == 0) {
					this.currmentTime = this.getTimeString() //获取当前时间
					this.nextTime = this.getTimeString('', this.totalHour) //下一个小时的时间
				} else {
					let currmentDate = this.getDate(0) + ' ' + this.currmentTime
					this.nextTime = this.getTimeString(currmentDate, this.totalHour) //下一个小时的时间
				}
			},
			// 减少时间
			reduce() {
				if (this.totalHour == 1) return //减少为一个小时时不可再减少
				this.totalHour--
				this.allHour = Number(this.totalHour) + Number(this.currentHour)
				if (this.currmentIndex == 0) {
					this.currmentTime = this.getTimeString() //获取当前时间
					this.nextTime = this.getTimeString('', this.totalHour) //下一个小时的时间
				} else {
					let currmentDate = this.getDate(0) + ' ' + this.currmentTime
					this.nextTime = this.getTimeString(currmentDate, this.totalHour) //下一个小时的时间
				}
				console.log(this.currentHour)
			},
			// 选择日期
			changeDate(e) {
				let index = e.detail.value
				console.log(index)
				if (this.tableInfo.day_yuyue) { //如果有预约
					if (this.isToday(this.getDate(0, index), this.tableInfo.day_yuyue)) {
						console.log('是同一天111111')
					} else {
						if (this.greaterToday(this.getDate(0, index), this.tableInfo.day_yuyue)) {
							console.log('预约时间大于今天')
							this.$tools.showToast('当前日期没有可预约的时段')
							return;
						} else {
							console.log('预约时间不大于今天')
						}
					}
				}
				if (this.dateIndex == index) {
					return;
				}
				this.dateIndex = Number(index)
				if (this.currmentIndex > 0) {
					this.totalHour = this.mealList[this.currmentIndex].duration
				} else {
					this.totalHour = 1 //选择的小时数恢复默认
				}
				if (this.order_type == 'make_appointment') { //如果是预约就选择当前日期下的格子
					let key = Object.keys(this.tableInfo.t_date)
					this.hoursList = this.tableInfo.t_date[key[this.dateIndex]] //获取当前天的格子
					this.currmentDate = this.getDate(1, this.dateIndex)
					console.log(this.currmentDate)
					if (this.dateIndex != 0) { //不是今天
						this.startTime = "00:00"
						this.currmentTime = "00:00"
						this.pastHour = -1
						this.currentHour = 0
						this.allHour = Number(this.totalHour) + Number(this.currentHour)
						let currmentDate = this.getDate(0) + ' ' + this.currmentTime
						this.nextTime = this.getTimeString(currmentDate, this.totalHour) //下一个小时的时间
						// this.getHoursData();
					} else {
						this.getHoursData();
						if (this.days_in_advance == 0 || this.days_in_advance == 1) {
							this.hoursList = this.tableInfo.t_date[key[0]]
						} else {
							this.hoursList = this.tableInfo.t_date[key[0]].concat(this.tableInfo.t_date[key[1]])
						}
					}
				}
				if (this.dateIndex == 0) {
					this.scrollIndex = 'lattice-' + Number(this.currentHour - 2)
				} else {
					this.scrollIndex = 'lattice-0'
				}
			},
			// 桌球详情
			tableDetails() {
				this.orderTime = Date.parse(new Date()) / 1000;
				this.$request.post(this.$api.tableDetails, {
					store_id: uni.getStorageSync('store_id'),
					equipment_id: this.equipment_id
				}, {}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code == 1) {
						this.tableInfo = data
						this.numText=""
						this.characters=""
						let nameList = this.tableInfo.equipment_name.split('')
						let isNaNEmpty = false //是否有数字
						isNaNEmpty = nameList.some(item => !isNaN(item))
						if (!isNaNEmpty || isNaN(nameList[0])) {
							for (let i in nameList) {
								if (i == 0) {
									this.numText += nameList[i]
								} else {
									this.characters += nameList[i]
								}
							}
						} else {
							for (let i in nameList) {
								if (!isNaN(nameList[i])) {
									this.numText += nameList[i]
								} else {
									this.characters += nameList[i]
								}
							}
						}
						this.days_in_advance = data.days_in_advance
						this.type = data.type
						uni.setStorageSync('type', this.type)
						this.getHoursData();
						let p_name = ''
						if (this.order_type == 'immediately') {
							p_name = '立即开台'
						} else {
							p_name = '预约开台'
						}
						this.mealList = [{
							p_name: p_name,
							p_price: this.tableInfo.price
						}]
						this.mealList.push(...data.set_meal)
						let key = Object.keys(this.tableInfo.t_date)
						if (this.days_in_advance == 0 || this.days_in_advance == 1) {
							this.hoursList = this.tableInfo.t_date[key[0]]
						} else {
							this.hoursList = this.tableInfo.t_date[key[0]].concat(this.tableInfo.t_date[key[1]])
						}
						if (data.days_in_advance == 1 && data.days_in_advance_type == 1) {
							this.dateList = [{
								riqis: '今天'
							}]
						} else if (data.days_in_advance == 2) {
							this.dateList = [{
								riqis: '今天'
							}, {
								riqis: '明天'
							}]
						} else if (data.days_in_advance == 3) {
							this.dateList = [{
								riqis: '今天'
							}, {
								riqis: '明天'
							}, {
								riqis: '后天'
							}]
						}
						if (data.type == 2) {
							this.minReservationTime = data.minimum_reservation_time
						}
					}
				})
			},
			// 继续下单
			continueOrder(){
				this.$jiuaiDebounce.canDoFunction({
					key: 'continueOrder', //基于此值判断是否可以操作，如两个方法传入了同样的key，则会混淆，建议传入调用此事件的方法名，简单好梳理
					time: 2000, //如果传入time字段，则为定时器后，自动解除锁定状态，单位（毫秒）
					success: () => {
						this.is_confirm=1
						this.orderData.is_confirm=1
						this.continueShow=false
						this.submitOrder();
					}
				})
			},
			closeContinue(){
				this.is_confirm=0
				this.orderData.is_confirm=0
				this.continueShow=false
			},
			getChangeList(){
				this.$request.post(this.$api.changeList, {
					store_id:uni.getStorageSync('store_id'),
					minute:this.serviceMinNum,
					equipment_id:this.equipment_id
				}, {
					token:true
				}).then(res => {
					console.log(res)
					if (res.code==1) {
						let {
							data = {}
						} = res;
						this.changeList=data
						this.changeLists=[]
						for (let i in this.changeList) {
							this.changeLists.push(this.changeList[i].equipment_name)
						}
					}
				})
			},
			showActionSheet(){
				let that=this
				console.log(this.changeLists)
				if(this.changeLists.length==0){
					this.$tools.showToast('当前没有空余台桌');
					this.continueShow=false
					return;
				}
				uni.showActionSheet({
					itemList: that.changeLists,
					success: function (res) {
						let index=res.tapIndex
						console.log(index)
						console.log(that.changeList)
						console.log(that.changeList[index])
						console.log(that.changeList[index].id)
						that.equipment_id=that.changeList[index].id
						that.tableDetails();
						that.continueShow=false
						console.log('选中了第' + (index + 1) + '个按钮');
					},
					fail: function (res) {
						console.log(res.errMsg);
					}
				});
			},
			// 提交参数验证
			goConfirm() {
				uni.showLoading({
					title: '加载中...',
					mask: true
				})
				let timestamp = Date.parse(new Date()) / 1000;
				if (Math.abs(timestamp - this.orderTime) > 300) {
					this.$tools.hideLoading()
					uni.showModal({
						title: '提示',
						content: "当前页面停留过久，请新选择时间",
						success: (res) => {
							if (res.confirm) {
								this.tableDetails();
							}
						}
					});
					return;
				}
				if (this.tableInfo.status == 3 || this.tableInfo.status == 99) {
					this.$tools.hideLoading()
					this.$tools.showToast('对不起，请您选择其他桌，本桌正在维护或者使用中')
					return;
				} else if (this.minReservationTime > this.totalHour) {
					this.$tools.hideLoading()
					this.$tools.showToast('最低预定时长为' + this.minReservationTime + '小时')
					return;
				}
				let start_time = ""
				let end_time = ""
				let service_date = ""
				if (this.order_type == 'make_appointment'||this.currmentIndex!=0) {
					start_time = this.currmentTime
				}
				if (this.currmentIndex == 0) {
					service_date = this.getDate(1, this.dateIndex); //获取当前日期
				} else {
					service_date = this.tableInfo.yuyue != '23:59' ? this.getDate(1, this.dateIndex) : this.getDate(1,
						1); //获取当前日期
				}
				this.$request.post(this.$api.confirmOrder, {
					store_id: uni.getStorageSync('store_id'),
					store_equipment_id: this.equipment_id,
					types: this.type,
					order_type: this.currmentIndex == 0 ? this.order_type : 'other_packages',
					tr: this.currmentIndex > 0 ? this.mealList[this.currmentIndex].tr : "",
					renew_order_id: this.renew_order_id,
					hour_start_time: start_time,
					hours: this.totalHour,
					day_type: this.dateIndex
				}, {
					token: true
				}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code == 1) {
						this.orderData={
							store_equipment_id: this.equipment_id,
							order_type: this.currmentIndex == 0 ? this.order_type : 'other_packages',
							order_price: this.currmentIndex <= 0 ? this.totalPrice : this.mealList[this.currmentIndex].p_price,
							yingfu_price: this.currmentIndex <= 0 ? this.totalPrice : this.mealList[this.currmentIndex].p_price,
							type: 1,
							coupon_id: 0,
							store_name: this.tableInfo.shop_name,
							num_hour: this.totalHour,
							equipment_name: this.tableInfo.equipment_name,
							service_date: service_date,
							tr: this.currmentIndex > 0 ? this.mealList[this.currmentIndex].tr : "",
							totalHour: this.totalHour,
							is_ci: this.allHour > 23 ? 1 : 0,
							types: this.type,
							renew_order_id: this.renew_order_id,
							hour_start_time: start_time,
							hours: this.totalHour,
							day_type: this.dateIndex,
							is_confirm:this.is_confirm,
							serviceMinNum:0,
							characters: this.characters,
							numText: this.numText
						}
						if(data&&data.serviceMinNum){
							this.serviceMinNum=data.serviceMinNum
							this.orderData.serviceMinNum=this.serviceMinNum
							this.orderTotalPrice=data.orderTotalPrice
							this.continueShow=true
							this.continueMsg=res.msg
							this.getChangeList();
							this.$tools.hideLoading()
							return;
						}else{
							this.submitOrder()
						}
					} else {
						uni.hideToast()
						uni.showModal({
							title: '提示',
							content: res.msg,
							success: function(res) {

							}
						});
					}
				}).finally(() => {
					setTimeout(() => {
						this.$tools.hideLoading()
					}, 1000)
				})
			},
			submitOrder() {
				if(this.is_confirm==1){
					this.orderData.order_price=this.orderTotalPrice
				}else{
					this.orderData.order_price=this.currmentIndex<=0?this.totalPrice:this.mealList[this.currmentIndex].p_price
				}
				this.orderData.tr ? this.orderData.num_hour = this.orderData.tr : this.orderData.num_hour = ""
				this.orderData.store_id = uni.getStorageSync('store_id')
				this.$request.post(this.$api.submitOrder, this.orderData, {
					token: true
				}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code == 1) {
						this.orderData.startTime = data.start_time
						this.orderData.endTime = data.end_time
						uni.navigateTo({
							url: '/moduleA/confirmOrder?orderData=' + JSON.stringify(this.orderData)
						})
					}
				}).finally(() => {
					setTimeout(()=>{
						this.is_confirm=0
						this.orderData.is_confirm=0
						this.$tools.hideLoading()
					}, 1000)
				})
			},
		}
	}
</script>

<style lang="scss">
	.content {
		padding: 28upx;
		padding-bottom: 400upx;
	}

	.table-info {
		.big {
			font-family: Arial, Arial;
			font-weight: bold;
			font-size: 136rpx;
			color: #F9FAFE;
		}

		.info {
			margin-left: 20upx;

			.table-name {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 34rpx;
				color: #F9FAFE;

				.status {
					display: inline-block;
					min-width: 90rpx;
					padding: 0 10upx;
					line-height: 48upx;
					height: 48rpx;
					background: linear-gradient(180deg, #4AA22A 0%, #69D037 100%);
					border-radius: 48rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 26rpx;
					color: #FFFFFF;
					text-align: center;
					margin-left: 18upx;
				}

				.busy {
					background: #FF8A57;
				}

				.repair {
					background: #848C95;
				}
			}

			.store-name {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 26rpx;
				color: #FFFFFF;
				margin-top: 20upx;
				opacity: .5;
			}
		}
	}

	.select-box {
		margin-top: 30upx;
		overflow-x: scroll;

		.select-item {
			width: 222rpx;
			height: 240rpx;
			background: #232428;
			border-radius: 20rpx;
			margin-right: 14upx;
			flex: none;

			.select-top {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 26rpx;
				color: #FFFFFF;
				padding-left: 32upx;

				.select-icon {
					width: 72upx;
					height: 72upx;
					padding: 14upx;
				}
			}

			.select-bottom {
				padding-left: 32upx;
				margin-top: 40upx;

				.name {
					font-family: PingFang SC, PingFang SC;
					font-weight: 600;
					font-size: 28rpx;
					color: #FFFFFF;
					@include ellipsis(1);
				}

				.price {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 26rpx;
					color: #FFFFFF;
					margin-top: 8upx;
					opacity: .4;
				}
			}
		}

		.active {
			background: linear-gradient(180deg, #3D46C7 0%, #7781FD 100%);
		}
	}

	.time-box {
		background: #232428;
		border-radius: 20rpx;
		margin-top: 14upx;
		padding: 40upx 32upx;

		.top-box {
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 26rpx;
			color: #8C8C8E;

			.title {
				font-family: PingFang SC, PingFang SC;
				font-weight: 600;
				font-size: 34rpx;
				color: #FFFFFF;
				margin-bottom: 12upx;
			}

			.hours {
				font-family: PingFang SC, PingFang SC;
				font-weight: 600;
				font-size: 38rpx;
				color: #FFF4F4;
			}
		}

		.date-select-box {
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 34rpx;
			color: #919294;
			margin-top: 24upx;

			.date-box {
				font-family: PingFang SC, PingFang SC;
				font-weight: 600;
				font-size: 34rpx;
				color: #FFFFFF;
				border-radius: 48rpx;
				border: 2rpx solid #4F5053;
				padding: 24upx;
				margin-left: 12upx;

				.down-icon {
					width: 30upx;
					height: 20upx;
					margin-left: 20upx;
				}
			}

			.time {
				border-radius: 48rpx;
				border: 2rpx solid #4F5053;
				padding: 16upx;
				margin-left: 4upx;
				margin-right: 12upx;

				.reduce-btn {
					text {
						display: inline-block;
						width: 64rpx;
						height: 64rpx;
						line-height: 64upx;
						text-align: center;
						background: #464F58;
						border-radius: 50%;
						margin-left: 4upx;
					}
				}

				.colon {
					font-family: PingFang SC, PingFang SC;
					font-weight: 600;
					font-size: 30rpx;
					color: #FFFFFF;
					margin: 0 4upx;
				}
			}
		}

		.lattice-box {
			padding: 40upx 0;
			border-top: 2rpx dashed #707070;
			border-bottom: 2rpx dashed #707070;
			margin-top: 38upx;
			overflow-x: scroll;
			width: 100%;
			white-space: nowrap;

			.lattice {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 48rpx;
				color: #4F4F53;
				margin-right: 50upx;
				flex: none;
				display: inline-block;
			}

			.blue {
				background: #7781FD !important;
				border-radius: 50%;
				width: 90upx;
				height: 90upx;
				line-height: 90upx;
				text-align: center;
				color: #FFFFFF;
				margin-right: 14upx;
				position: relative;
				z-index: 999;
				.lable {
					position: absolute;
					background: #3D46C7;
					height: 90upx;
					width: 100upx;
					top: 0;
					z-index: 1;
					border-radius: 6%;
					left: 54upx;
					opacity: .5;
				}
			}

			.white {
				color: #FFFFFF;
			}

			.red {
				background: #FF4726 !important;
				border-radius: 50%;
				width: 90upx;
				height: 90upx;
				line-height: 90upx;
				text-align: center;
				color: #FFFFFF;
				margin-right: 14upx;
			}
		}

		.select-time-box {
			margin-top: 28upx;

			.select-time {
				font-family: PingFang SC, PingFang SC;
				font-weight: 600;
				font-size: 30rpx;
				color: #FFFFFF;

				.title {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 26rpx;
					color: #919294;
					margin-bottom: 16upx;
				}
			}

			.operation-box {
				.reduce-btn {
					width: 80upx;
					height: 80upx;
					line-height: 80upx;
					text-align: center;
					border-radius: 16upx;
					font-size: 48upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					border-radius: 50%;
					border: 1rpx solid rgba(255, 255, 255, .5);
				}

				.operation-num {
					margin: 0 24upx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 600;
					font-size: 38rpx;
					color: #FFFFFF;
				}

				.increase-btn {
					width: 80upx;
					height: 80upx;
					line-height: 80upx;
					text-align: center;
					background: linear-gradient(180deg, #E6EFFF 0%, #FFFFFF 100%);
					border-radius: 16upx;
					font-size: 48upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #232428;
					border-radius: 50%;
				}
			}
		}
	}

	.explain-box {
		margin-top: 28upx;
		border-top: 2upx solid #55525D;

		.explain-cont {
			margin-top: 36upx;
			font-size: 28upx;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 44upx;
			color: #969696;

			.explain-text {
				font-size: 28upx;
				font-family: PingFang SC;
				font-weight: 400;
				line-height: 44upx;
				color: #969696;
			}

			rich-text {
				p {
					color: #969696;
				}
			}
		}
	}

	.btn-box {
		position: fixed;
		left: 20upx;
		right: 20upx;
		bottom: 0;
		background-color: #232428;
		padding: 40upx 20upx;
		justify-content: center;
		border-radius: 20upx;

		.total-box {
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 34rpx;
			color: #FFFFFF;

			.price {
				font-family: PingFang SC, PingFang SC;
				font-weight: 600;
				font-size: 48rpx;
				color: #FFFFFF;
				margin-left: 20upx;
			}

			.original-price {
				text-decoration: line-through;
				color: #919294;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 34rpx;
				margin-left: 20upx;
			}
		}

		.pay-btn {
			height: 144rpx;
			line-height: 144rpx;
			background: linear-gradient(90deg, #4AA22A 0%, #69D037 100%);
			border-radius: 72rpx;
			font-size: 36upx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			text-align: center;
			margin: auto;
			margin-top: 24upx;
		}
	}
	.tips-box{
		width: 630upx;
		height: 440upx;
		background:#232428;
		border-radius: 16upx;
		position: fixed;
		top: 400upx;
		left: 0;
		right: 0;
		margin: auto;
		z-index: 999;
		.tips-name{
			font-size: 36upx;
			font-family: PingFang SC;
			font-weight: 800;
			line-height: 50upx;
			color: #FFFFFF;
			margin-top: 68upx;
		}
		.close-btn{
			width: 40upx;
			height: 40upx;
			position: absolute;
			top: 30upx;
			right: 30upx;
		}
		.tips-text{
			font-size: 28upx;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 50upx;
			color: #FFFFFF;
			margin-top: 14upx;
			padding: 0 30upx;
		}
		.tips-btn-box{
			margin-top: 60upx;
			.tips-btn{
				width: 200upx;
				height: 80upx;
				line-height: 80upx;
				text-align: center;
				background: linear-gradient(90deg, #4AA22A 0%, #69D037 100%);
				border-radius: 16upx;
				font-size: 28upx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				&:nth-of-type(1){
					margin-right: 30upx;
				}
			}
		}
	}
</style>